package com.itboye.ihomebank.home;

import java.util.Observable;
import java.util.Observer;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.myzhujia.ActivityMySign;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.SPUtils;

/**
 * 
 */
public class ActivityShenQingZuFang extends BaseOtherActivity implements
		OnClickListener, Observer {
	Button btn_submit;
	EditText edit_content;
	TextView add_shap_title_tv;
	ImageView close_icon;
	HousePresenter housePresenter;
	private String houseNo;
	private String uid;

	@Override
	public void onClick(View v) {
		Intent intent = null;
		switch (v.getId()) {
		case R.id.close_icon:
			finish();
			break;
		case R.id.btn_submit:
			houseNo = getIntent().getStringExtra("house_no");
			uid = SPUtils.get(this, null, SPContants.USER_ID, "") + "";
			String remark = edit_content.getText().toString();
			if (remark.equals("")) {
				ByAlert.alert("请输入申请理由");
				return;
			}
			housePresenter.shenQingQianYue(uid, houseNo, remark, "0");
			// intent=new Intent(this,ActivityShenQingZuFang.class);
			// startActivity(intent);
			break;
		default:
			break;
		}

	}

	@Override
	protected int layout_id() {
		// TODO Auto-generated method stub
		return R.layout.activity_reson;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		// TODO Auto-generated method stub

		add_shap_title_tv.setText("提交申请");
		housePresenter = new HousePresenter(this);
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == HousePresenter.qianYueShenQing_success) {
				ByAlert.alert(entity.getData());
				finish();
			} else if (entity.getEventType() == HousePresenter.qianYueShenQing_fail) {
				ByAlert.alert(entity.getData());
			}
		}
	}

}
